import {View} from '@tarojs/components';
import Taro from '@tarojs/taro';
import './modal.scss';


class Modal extends Taro.Component {
    static options = {
        addGlobalClass: true
    }
    config = {
        component: true,
        componentGenerics: {
            Modal: true
        }
    }

    state = {
    }

    componentWillMount() {

    }

    cancel = () => {
        if(this.props.onCancel){
            this.props.onCancel();
        }
    }


    confirm = () => {
        if(this.props.onConfirm){
            this.props.onConfirm();
        }
    };

    render() {
        const {message, messageText, cancelBtn=true, cancelText=null, confirmText=null} = this.props;
        return (
            <View className="curtain flex-center">
                <View className="popup">
                    <View className="popup-title">
                        <View>{message}</View>
                        {messageText &&(
                            <View className="popup-text-center">{messageText}</View>
                        )}
                    </View>
                    <View className='at-row popup-btn'>
                        {cancelBtn && (
                            <View className='at-col btn-off' onClick={this.cancel}>{cancelText || '取消'}</View>
                        )}
                        <View className='at-col btn-box' onClick={this.confirm}>{confirmText || '确认'}</View>
                    </View>
                </View>
            </View>
        )
    }
}

export default Modal;

